home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-05-22 | 8.2 KB | 399 lines | [TEXT/MPCC] |
- //
- // File: MacApplication.c
- //
- // Contains: Functions that could be overridden in a specific application.
- //
- // Written by: Tim Monroe
- // Based (heavily!) on the MovieShell code written by Apple DTS
- //
- // Copyright: © 1994-1996 by Apple Computer, Inc., all rights reserved.
- //
- // Change History (most recent first):
- //
- // <4> 12/05/96 rtm added hooks into MacFramework.c: StopApplication, InitApplicationWindowObject
- // <3> 12/02/96 rtm added cursor updating to DoIdle
- // <2> 11/27/96 rtm conversion to personal coding style;
- // added preliminary QTVR support
- // <1> 12/21/94 khs first file
- //
- //
-
- // header files
- #include "MacApplication.h"
- #include "MacFramework.h"
- #include "AppConfiguration.h"
- #include "DTSQTUtilities.h"
- #include "QTVRUtilities.h"
-
- // Header file for the specific test functions.
- #include "TestFunctions.h"
-
- // global variables
- long gMaxMilliSecToUse = kMaxMilliSecToUse;
-
-
- //////////
- //
- // InitApplication
- // Do any application-specific initialization.
- //
- //////////
-
- void InitApplication (void)
- {
- // make sure that the QTVR Manager is present in the present operating environment
- if (!QTVRUtils_IsQTVRMgrInstalled()) {
- ShowWarning("\pThe QuickTime VR Manager cannot be found.", 0);
- //ExitToShell();
- }
- }
-
-
- //////////
- //
- // StopApplication
- // Do any application-specific shut-down.
- //
- //////////
-
- void StopApplication (void)
- {
- // @@@INSERT APPLICATION-SPECIFIC SHUT-DOWN FUNCTIONALITY HERE
-
- }
-
-
- //////////
- //
- // DoIdle
- // Do any processing that can/should occur at idle time.
- //
- //////////
-
- void DoIdle (WindowRef theWindow)
- {
- GrafPtr mySavedPort;
- WindowObject myWindowObject;
- MovieController myMC = NULL;
- Point myPoint;
-
- GetPort(&mySavedPort);
- SetPort(theWindow);
-
- myWindowObject = (WindowObject) GetWRefCon(theWindow);
- if (myWindowObject != NULL) {
-
- myMC = (**myWindowObject).fController;
- if (myMC != NULL) {
-
- MoviesTask(MCGetMovie(myMC), gMaxMilliSecToUse);
-
- //restore the cursor to the arrow if it's outside the movie window
- //and the mouse button isn't still down;
- //this is needed only for VR movies, but should probably always be done
- if (theWindow == FrontWindow()) {
- GetMouse(&myPoint);
- if (!PtInMovie(MCGetMovie(myMC), myPoint) && !StillDown())
- InitCursor();
- }
- }
- }
-
- // @@@INSERT ANY OTHER IDLE-BASED FUNCTIONALITY HERE
-
- SetPort(mySavedPort);
- }
-
-
- //////////
- //
- // DoUpdateWindow
- // Update the specified window.
- //
- //////////
-
- void DoUpdateWindow (WindowRef theWindow, Rect *theRefreshArea)
- {
- GrafPtr mySavedPort;
-
- GetPort(&mySavedPort);
- SetPort(theWindow);
-
- BeginUpdate(theWindow);
-
- EraseRect(theRefreshArea); // this is important, for non-rectangular movies
-
- // @@@INSERT WINDOW-SPECIFIC DRAWING FUNCTIONALITY HERE
-
- EndUpdate(theWindow);
- SetPort(mySavedPort);
- }
-
-
- //////////
- //
- // HandleContentClick
- // Handle mouse button clicks in the specified window.
- //
- //////////
-
- void HandleContentClick (WindowRef theWindow, EventRecord *theEvent)
- {
- GrafPtr mySavedPort;
-
- GetPort(&mySavedPort);
- SetPort(theWindow);
-
- // @@@INSERT APPLICATION-SPECIFIC CONTENT CLICKING FUNCTIONALITY HERE
-
- SetPort(mySavedPort);
- }
-
-
- //////////
- //
- // HandleQTVRKeyPress
- // Handle QuickTime VR-specific key presses.
- // Returns true if the key press was handled, false otherwise.
- //
- //////////
-
- Boolean HandleQTVRKeyPress (EventRecord *theEvent)
- {
- Boolean isHandled = true;
- char myCharCode;
-
- myCharCode = theEvent->message & charCodeMask;
-
- switch (myCharCode) {
- case '-':
- // decrease Pan 1 degree
- //mQTVRChangePan(nil, -1.0);
- break;
- case '+':
- // decrease Pan 1 degree
- //mQTVRChangePan(nil, 1.0);
- break;
-
- // take keypad keys as a nudge in the appropriate direction
- case '1':
- //mQTVRNudge(kQTVRDownLeft);
- break;
- case '2':
- //mQTVRNudge(kQTVRDown);
- break;
- case '3':
- //mQTVRNudge(kQTVRDownRight);
- break;
- case '4':
- //mQTVRNudge(kQTVRLeft);
- break;
- case '6':
- //mQTVRNudge(kQTVRRight);
- break;
- case '7':
- //mQTVRNudge(kQTVRUpLeft);
- SysBeep(30);
- break;
- case '8':
- //mQTVRNudge(kQTVRUp);
- break;
- case '9':
- //mQTVRNudge(kQTVRUpRight);
- break;
-
- default:
- isHandled = false;
- break;
- }
-
- return(isHandled);
- }
-
-
- //////////
- //
- // CreateMovieWindow
- // Create a window to display a movie in.
- //
- //////////
-
- WindowRef CreateMovieWindow (Rect *theRect, Str255 theTitle)
- {
- WindowRef myWindow;
-
- myWindow = NewCWindow(NULL, theRect, theTitle, false, noGrowDocProc, (WindowPtr)-1L, true, 0);
- return(myWindow);
- }
-
-
- //////////
- //
- // HandleApplicationMenu
- // Handle selections in the application's menus.
- //
- //////////
-
- void HandleApplicationMenu (short theMenuID, short theMenuItem)
- {
- MovieController myMC = NULL;
-
- switch (theMenuID) {
- case mTesting:
- switch(theMenuItem) {
- case iTest1:
- // @@@INSERT YOUR TEST FUNCTION 1 HERE
- myMC = GetMCFromFrontWindow();
- if (myMC != NULL) {
- QTVRUtils_HideControllerBar(myMC);
- }
- break;
-
- case iTest2:
- // @@@INSERT YOUR TEST FUNCTION 2 HERE
- myMC = GetMCFromFrontWindow();
- if (myMC != NULL) {
- QTVRUtils_ShowControllerBar(myMC);
- }
- break;
-
- case iTest3:
- // @@@INSERT YOUR TEST FUNCTION 3 HERE
- myMC = GetMCFromFrontWindow();
- if (myMC != NULL) {
- QTVRUtils_HideControllerButton(myMC, kQTVRHotSpotButton);
- }
- break;
-
- case iTest4:
- // @@@INSERT YOUR TEST FUNCTION 3 HERE
- myMC = GetMCFromFrontWindow();
- if (myMC != NULL) {
- QTVRUtils_ShowControllerButton(myMC, kQTVRHotSpotButton);
- }
- break;
- }
- break;
- }
- }
-
-
- //////////
- //
- // AdjustApplicationMenus
- // Adjust state of items in the application's menus.
- //
- //////////
-
- void AdjustApplicationMenus (void)
- {
- WindowRef myWindow = NULL;
- MovieController myMC = NULL;
-
- myMC = GetMCFromFrontWindow();
- if (myMC != NULL) {
- EnableItem(GetMHandle(mTesting), iTest1);
- EnableItem(GetMHandle(mTesting), iTest2);
- EnableItem(GetMHandle(mTesting), iTest3);
- EnableItem(GetMHandle(mTesting), iTest4);
- } else {
- DisableItem(GetMHandle(mTesting), iTest1);
- DisableItem(GetMHandle(mTesting), iTest2);
- DisableItem(GetMHandle(mTesting), iTest3);
- DisableItem(GetMHandle(mTesting), iTest4);
- }
-
- DisableItem(GetMHandle(mFile), iNew); // we don't allow creating new VR files here...
- DisableItem(GetMHandle(mFile), iPrint); // currently printing causes crashes; FIX!
- }
-
-
- //////////
- //
- // AddControllerFunctionality
- // Configure the movie controller.
- //
- //////////
-
- void AddControllerFunctionality (MovieController theMC)
- {
- long myControllerFlags;
-
- // CLUT table use
- MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
- MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette));
-
- // enable keyboard event handling
- MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true);
-
- // disable drag support
- MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);
- }
-
-
- //////////
- //
- // InitApplicationWindowObject
- // Do any application-specific initialization of the window object.
- //
- //////////
-
- void InitApplicationWindowObject (WindowObject theWindowObject)
- {
- // @@@INSERT APPLICATION-SPECIFIC WINDOW OBJECT INITIALIZATION HERE
- }
-
-
- //////////
- //
- // RemoveApplicationWindowObject
- // Do any application-specific clean-up of the window object.
- //
- //////////
-
- void RemoveApplicationWindowObject (WindowObject theWindowObject)
- {
- OSErr myErr = noErr;
- QTVRInstance myInstance = NULL;
-
- if (theWindowObject == NULL)
- return;
-
- myInstance = (**theWindowObject).fInstance;
-
- // @@@INSERT APPLICATION-SPECIFIC WINDOW OBJECT CLEAN-UP HERE
-
- // DoDestroyMovieWindow in MacFramework.c releases the window object itself
- }
-
-
- //////////
- //
- // ApplicationMCActionFilterProc
- // Intercept some mc actions for the QuickTime VR movie controller.
- //
- //////////
-
- pascal Boolean ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, WindowRef theWindow)
- {
- Boolean isHandled = false;
-
- switch (theAction) {
-
- // handle window resizing
- case mcActionControllerSizeChanged: {
- Rect myMovieBounds;
-
- MCGetControllerBoundsRect(theMC, &myMovieBounds);
- SizeWindow((WindowPtr)theWindow, myMovieBounds.right - myMovieBounds.left,
- myMovieBounds.bottom - myMovieBounds.top, true);
- break;
- }
-
- default:
- break;
- }
-
- return(isHandled);
- }
-